function toggleComment(itemId){
	var fadespeed = 600;
	var common_detal = $("#comment_"+itemId);
	
	if (common_detal.css('display') == 'none') {
		getComment(itemId);
		common_detal.slideDown(fadespeed);
	}else{
		common_detal.slideUp(fadespeed);	
	};

}
function toggleActivity(itemId){
	var fadespeed = 600;
	var item_detal = $("#item_detail_"+itemId);
	
	if (item_detal.css('display') == 'none') {
		item_detal.slideDown(fadespeed);
	}else{
		item_detal.slideUp(fadespeed);	
	};

	var common_detal = $("#comment_"+itemId);
	if (common_detal.css('display') != 'none') {
		common_detal.slideUp(fadespeed);	
	}
}

function getComment(aid){
	$.ajax({
	  type: 'POST',
	  url: baseurl+'ajax/get_comments',
	  data: {
			param:{
				aid:aid
			},
			key:'47edbd4fcb4e0ba3c240949542545828'
			},
	  success: function(result){
			$('#comment_'+aid).html(result);
		},
	  dataType: 'html'
	});
}

function sendComment(aid){
	$.ajax({
		type: 'POST',
		url: baseurl+'ajax/add_comment',
		data: {
			param:{
				aid:aid,
				content:$('#comment_content_'+aid).val()
			},
			key:$('#key_'+aid).val()
		},
	  success: function(result){
				var jsonstr = $.toJSON(result);
				obj = $.parseJSON(jsonstr); 
			if (obj.code != '1') {
				alert(obj.msg);
			};
			getComment(aid);
		},
	  dataType: 'json'
	});
}
function delComment(aid,cid){
	$.ajax({
		type: 'POST',
		url: baseurl+'ajax/del_comment',
		data: {
			param:{
				aid:aid,
				cid:cid
			},
			key:$('#key_'+aid).val()
		},
	  success: function(result){
				var jsonstr = $.toJSON(result);
				obj = $.parseJSON(jsonstr); 
			if (obj.code != '1') {
				alert(obj.msg);
			}else{
				$('#comment_'+cid).hide('normal');
			};
			getComment(aid);
		},
	  dataType: 'json'
	});
}
function collect(aid){
	$.ajax({
		type: 'POST',
		url: baseurl+'ajax/add_collection',
		data: {
			param:{
				aid:aid
			},
			key:$('#activity_key_'+aid).val()
		},
	  success: function(result){
				var jsonstr = $.toJSON(result);
				obj = $.parseJSON(jsonstr); 
			if (obj.code == '1') {
				$('#collection_'+aid).html('已收藏');
			}else if(obj.code == '2'){
				$('#ajax_login').dialog('open');
			}else{
				alert(obj.msg);
			};
		},
	  dataType: 'json'
	});	
}

function cancel_collect(aid){
	$.ajax({
		type: 'POST',
		url: baseurl+'ajax/cancel_collection',
		data: {
			param:{
				aid:aid
			},
			key:$('#activity_key_'+aid).val()
		},
	  success: function(result){
				var jsonstr = $.toJSON(result);
				obj = $.parseJSON(jsonstr); 
			if (obj.code != '1') {
				alert(obj.msg);
			}else{
				$('#item_'+aid).hide('normal');
			};
		},
	  dataType: 'json'
	});	
}
//锚点平滑过度
$(document).ready(function() {
    $('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({
                    scrollTop: targetOffset
                },
                1000);
                return false;
            }
        }
    });
});

$("#ajax_login").dialog(
	{
		autoOpen: false,
		closeOnEscape: true,
		draggable: true,
		modal: true,
		title: '请先登录',
		width: 300,
		resizable:false,
		dialogClass:'ajax_login'
	}
);

// 分享函数
function shareTo(shareId, url, title, pic){
	switch (shareId){
	   case 'sina':
			var param = {
				url: url,
				type:'3',
				count:'0', /**是否显示分享数，1显示(可选)*/
				appkey:'1327921223', /**您申请的应用appkey,显示分享来源(可选)*/
				title:title, /**分享的文字内容(可选，默认为所在页面的title)*/
				pic:pic, /**分享图片的路径(可选)*/
				ralateUid:'2157621611', /**关联用户的UID，分享微博会@该用户(可选)*/
				rnd:new Date().valueOf()
			}
			var api = 'http://service.weibo.com/share/share.php?';
	     break
	   case 'qq':
		     var param = {
				title:title,
				url:encodeURIComponent(url),
				appkey:encodeURI("17e735fcbd6b49ada84bcd32301aed0f"),
				pic:encodeURI(pic),
				site:'http://www.6block.com'
			}
			var api = 'http://v.t.qq.com/share/share.php?';
	     break
	   case 'qzone':
			var param = {
				url:url,
				desc:'',/*默认分享理由(可选)*/
				summary:'',/*摘要(可选)*/
				title:title,/*分享标题(可选)*/
				site:'http://www.6block.com',/*分享来源 如：腾讯网(可选)*/
				pics:pic /*分享图片的路径(可选)*/
			}
			var api = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?';
	     break
	   case 'kaixin001':
			var param = {
				rtitle:title,
				rcontent:title,/*默认分享理由(可选)*/
				rurl:url/*摘要(可选)*/
			}
			var api = 'http://www.kaixin001.com/repaste/bshare.php?';
	     break
	   case 'douban':
			var param = {
				url:url,
				title:title,/*默认分享理由(可选)*/
				sel:encodeURIComponent(title),
				v:1
			}
			var api = 'http://www.douban.com/recommend/?';
	     break
	   default:
		var param = {}
		var api = '';
	}
	if (param && api) {
		var urlparam = [];
		for( var p in param ){
			urlparam.push(p + '=' + encodeURIComponent( param[p] || '' ) )
		}
		var shareapi = api+ urlparam.join('&');
		window.open( shareapi,'', 'width=700, height=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );		
	};
}


// 分享活动

$("#shar_act").dialog(
	{
		autoOpen: true,
		closeOnEscape: true,
		draggable: true,
		modal: true,
		title: '您分享的活动',
		width: 800,
		resizable:false
	}
);
// 侧边浮动工具栏


$(document).ready(function(){
	//隐藏 #back-top 先
	$("#float_tool").hide();
	// 滚动条距顶100px显示 #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#float_tool').fadeIn();
			} else {
				$('#float_tool').fadeOut();
			}
		});
		// 点击事件 回到顶部
		$('#backtotop').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 600);
			return false;
		});
	});
	
	$('#category_menu').hover(
		function (){
			$('#sub_menu').slideDown();
		},
		function (){
			$('#sub_menu').slideUp();
		}
		);
	// if($("#fl_menu")){
	// 	// 导航
	// 	//config
	// 	var float_speed=1500; //milliseconds
	// 	var menu_fade_speed=500; //milliseconds
	// 	var closed_menu_opacity=0.75;
	// 
	// 	//cache vars
	// 	var fl_menu=$("#fl_menu");
	// 	var fl_menu_list=$("#menu_list");
	// 	var fl_menu_title=$("#menu_title");
	// 
	// 
	// 	menuPosition=$('#fl_menu').position().top;
	// 
	// 	fl_menu.click(function(){
	// 		if (fl_menu_list.css('display') == 'none') {
	// 			fl_menu_title.fadeTo(menu_fade_speed, 1);
	// 			fl_menu_list.fadeIn(menu_fade_speed);				
	// 		}else{
	// 			fl_menu_title.fadeTo(menu_fade_speed, closed_menu_opacity);
	// 			fl_menu_list.fadeOut(menu_fade_speed);	
	// 		}
	// 	}
	// 	);		
	// }
});